#coding=utf8

from matplotlib import pyplot
import matplotlib.animation as animation
import numpy

def graphs():
    """
    柱形图
    """
    # dict = {'key1': 1.5, 'key2': 9, 'key3': 8.1, 'key4' : 0.4, 'key5' : 2, 'key6' : 3}
    # keys = list(dict.keys())
    # values = list(dict.values())
    # #
    # # num_list = [1.5, 9, 8.1, 0.4, 2, 3]
    # pyplot.bar(range(len(dict)), values, color='rgb', tick_label = keys)
    # pyplot.show()
    """
    柱形图-堆叠
    """
    # dict = {'key1': 1.5, 'key2': 9, 'key3': 8.1, 'key4' : 0.4, 'key5' : 2, 'key6' : 3}
    # keys = list(dict.keys())
    # values = list(dict.values())
    #
    # num_list = [1.5, 9, 8.1, 0.4, 2, 3]
    #
    # pyplot.bar(range(len(dict)), values, label='red',fc = 'y')
    # pyplot.bar(range(len(dict)), num_list, bottom=values, label='green',tick_label = keys,fc = 'r')
    # pyplot.legend()
    # pyplot.show()

    """
    饼图
    """
    # dict = {"A": 15, "B": 30.55, "C": 44.44, "D": 10 }
    # key = tuple(dict.keys())
    #
    # value = list(dict.values())
    # explode = [0, 0.1, 0, 0]
    # pyplot.axes(aspect=10)
    # pyplot.pie(x=value, labels=key, explode=explode,autopct='%3.1f%%',
    #         shadow=True, labeldistance=1.1, startangle = 90,pctdistance = 0.6,
    #         colors = ['r', 'b', 'g', 'y'])
    #
    # pyplot.show()
    """
    散点图
    """
    # x = numpy.random.randn(1000)
    #
    # y = numpy.random.randn(1000)
    # y2 = numpy.random.randn(250, 4)
    #
    # pyplot.scatter(x, y, c="m", label = 'm')
    # pyplot.scatter(x, y2, color='b',label='red')
    # pyplot.legend(loc='upper right', ncol=1, fancybox=True, shadow=True)
    #
    # pyplot.xlabel('x')
    # pyplot.ylabel('y')
    #
    # pyplot.show()
    """
    折线图
    """
    # x = numpy.linspace(0, 2 * numpy.pi, 100)
    #
    # y1, y2 = numpy.sin(x), numpy.cos(x)
    #
    # pyplot.plot(x, y1, 'bp--', c='r',  label = 'sin')
    #
    # pyplot.plot(x, y2, c='g', label = 'cos')
    # pyplot.legend(loc='upper right', ncol=1, fancybox=True, shadow=True)
    #
    # pyplot.title("sin&cos")
    # pyplot.xlabel('x')
    # pyplot.ylabel('y')
    #
    # pyplot.show()

    """
    密度
    """
    fig,ax = pyplot.subplots()


    data1 = numpy.random.normal(0, 1, 1000) #创建一组平均数为0，标准差为1，总个数为1000的符合标准正态分布的数据
    data2 = numpy.random.normal(0, 2, 500)

    ax.hist(data1, color = 'r', bins = 25, normed = True, alpha = 0.6, label = 'r')
    ax.hist(data2, color = 'g', bins = 10, normed = True, alpha = 0.6, label = 'g')
    pyplot.legend(loc='upper right', ncol=1, fancybox=True, shadow=True)

    pyplot.show()

    # data = numpy.random.randn(1000)
    # pyplot.distplot(data)
    # pyplot.show()


if __name__ == '__main__':
    graphs()
